package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseAdapter;
import com.neusoft.yuejian_01.javabean.ClubVideoBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.VideoViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 */

public class VideoAdapter extends BaseAdapter {
    public VideoAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_videolist, parent, false);
        //VideoView videoView = (VideoView) itemView.findViewById(R.id.videoView);
        VideoViewHolder viewHolder = new VideoViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(final RecyclerView.ViewHolder holder, final List data, final int position) {
        final ClubVideoBean videolist = (ClubVideoBean) data.get(position);
        final VideoViewHolder viewHolder = (VideoViewHolder) holder;
        final String cv_address = videolist.getCv_address();
        Uri uri = Uri.parse(ConstPhoto.BASE_URL+ConstPhoto.VideoFile+cv_address);
        viewHolder.videoView.setMediaController(new MediaController(context));
        viewHolder.videoView.setVideoURI(uri);
        viewHolder.videoView.requestFocus();
        //viewHolder.videoView.start();
        viewHolder.videoPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewHolder.videoView.start();
                viewHolder.videoPlay.setVisibility(View.GONE);
                viewHolder.videoBg.setVisibility(View.GONE);
            }
        });
    }


}
